<?php

namespace app\common\model\Coupon;

use think\Model;

class Coupon extends Model
{
    protected $name = "coupon";

    protected $autoWriteTimestamp = true;
    protected $createTime = 'createtime';

    protected $updateTime = false;

    protected $append = [
        'createtime_text', // 开始时间
        'endtime_text', // 结束时间
        'thumb_text', // 缩略图
        'createtimes', // 开时时间
    ];


    // 订单状态数据
    public function statuslist()
    {
        return [
            '1' => __('正在活动中'),
            '0' => __('结束活动'),
        ];
    }

    protected function getCreatetimeTextAttr($value, $data)
    {
        $createtime = !empty($data['createtime']) ? $data['createtime'] : '';

        if ($createtime) {
            return date('Y-m-d', $createtime);
        } else {
            return '';
        }
    }

    protected function getEndtimeTextAttr($value, $data)
    {
        $endtime = !empty($data['endtime']) ? $data['endtime'] : '';
        if ($endtime) {
            return date('Y-m-d', $endtime);
        } else {
            return '';
        }
    }


    public function getThumbTextAttr($value, $data)
    {
        $url = request()->domain();

        $thumbs = !empty($data['thumb']) ? $data['thumb'] : '/assets/img/coupon.png';

        return $url. $thumbs;
    }

    public function getCreatetimesAttr($value,$data)
    {
        $createtime = !empty($data['createtime']) ? $data['createtime'] : '';

        return  $createtime;
    }
}
